package com.zkk.web;

import com.zkk.pojo.User;
import com.zkk.service.UserService;
import com.zkk.service.impl.UserServiceImpl;
import com.zkk.utils.PageBeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAll")
public class findAll extends HttpServlet {
    @Override  //注意dopost请求不能问号传数据，
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        int cuPage = 0;
        if(currentPage==null || "".equals(currentPage)){
            cuPage=1;
            //默认是首页
        }else {
            cuPage = Integer.valueOf(currentPage);
        }
        int pSize =0;
        if(pageSize == null || "".equals(pageSize)){
            pSize = 5;
            //默认是十条
        }else {
            pSize = Integer.valueOf(pageSize);
        }
        //分页对象
        PageBeanUtils<User> pageBeanUtils = new PageBeanUtils<>();
        pageBeanUtils.setCurrentPage(cuPage);
        pageBeanUtils.setPageSize(pSize);
        //调用业务
        UserService userService = new UserServiceImpl();
        pageBeanUtils = userService.findAll(pageBeanUtils);





        /* List<User> all = userService.findAll();*/
        req.setAttribute("pageBeanUtils",pageBeanUtils);

        req.getRequestDispatcher("/showAll.jsp").forward(req,resp);


    }
    //经验：如果什么错都不报，看下是否请求跑到doGet或者doPost上面了，还有如果某些值没显示，很有可能为了获得值的Servlet没有执行
    //开始的请求是post,那么后面的其他Servlet的方法也是用doPost方法
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //分页


    }
}
